package com.css.crm.ws.customer;

import java.util.List;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;

import org.apache.log4j.Logger;

import com.css.crm.service.CustomerService;
import com.css.crm.service.impl.CustomerServiceImpl;
import com.css.crm.utility.WebserviceUtil;
import com.css.crm.vo.CustomerResponseVo;
import com.css.crm.vo.CustomerVo;

@Path(value = "/searchCustomer")
public class SearchCustomer {

	protected Logger log = Logger.getLogger(this.getClass().toString());

	@GET
	@Produces(MediaType.TEXT_PLAIN)
	public String searchCustomer(@QueryParam("keyWord") String keyWord) {
		try {
			CustomerService customerService = new CustomerServiceImpl();
			List<CustomerVo> customerVos = customerService.searchCustomerBySolr(keyWord);
			CustomerResponseVo customerResponseVo = new CustomerResponseVo();
			customerResponseVo.setCustomerList(customerVos);
			return WebserviceUtil.marshal(customerResponseVo);
		} catch (Exception e) {
			e.printStackTrace();
			log.error(e.getMessage());
			return null;
		}
	}

}